package com.szzg10.jsp.chapter10;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

public class Menu extends TagSupport {

	private List<String> items;
	
	public void addMenuItem(String name) {
		items.add(name);
	}
	
	@Override
	public int doStartTag() throws JspException {
		items = new ArrayList<String>();
		
		return EVAL_BODY_INCLUDE;
	}
	
	@Override
	public int doEndTag() throws JspException {
		try {
			pageContext.getOut().println("Menu items are: " + items);
		} catch (IOException e) {
			throw new JspException("Exception: " + e.toString());
		}
		
		return EVAL_PAGE;
	}
}
